//
//  ChargeController.m
//  AntsExpress
//
//  Created by slccper on 16/3/9.
//  Copyright © 2016年 slccper. All rights reserved.
//

#import "ChargeController.h"
#import "cImageView.h"
#import "clsFileFun.h"
#import "TPKeyboardAvoidingScrollView.h"
#import "UIView-ViewFrameGeometry.h"
@interface ChargeController ()<cImageViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *chang;
@property (weak, nonatomic) IBOutlet UITextField *kuan;
@property (weak, nonatomic) IBOutlet UITextField *gao;
@property (weak, nonatomic) IBOutlet cImageView *pic;
@property (weak, nonatomic) IBOutlet UITextField *Weight;
@property (weak, nonatomic) IBOutlet UILabel *memberno;
@property (weak, nonatomic) IBOutlet UILabel *membername;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *Money;
@end

@implementation ChargeController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[clsOtherFun getMemberId] integerValue]!=0) {
        self.memberno.text = [NSString stringWithFormat:@"會員編號：%ld",(long)[[clsOtherFun getMemberId] integerValue]+600000];
    }else{
        self.memberno.text = [NSString stringWithFormat:@"會員編號："];
    }
    self.membername.text = [NSString stringWithFormat:@"%@%@",@"收件人：",[clsOtherFun getName]];
    
    self.title=@"如何收費";
    if (self.branch.Contnet) {
        NSString *contnet = [self.branch.Contnet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        NSArray *array = [contnet componentsSeparatedByString:@"/"];
        NSString *name = [array lastObject];
        NSString *url = [NSString stringWithFormat:@"%@",[array firstObject]];
        for (int i =1;i<array.count-1;i++) {
            url = [NSString stringWithFormat:@"%@/%@",url,array[i]];
        }
        self.pic.activityView.color = [UIColor blackColor];
        self.pic.serverDirectory = url;
        self.pic.localDirectory = [clsFileFun getShowImage];
        self.pic.saveName = name;
        self.pic.noNetImage = [UIImage imageNamed:@""];
        self.pic.errorImage = self.pic.noNetImage;
        self.pic.noImage = self.pic.noNetImage;
        self.pic.contentMode=UIViewContentModeScaleAspectFit;
        self.pic.delegate=self;
        [self.pic loadImage];
    }
    
    // Do any additional setup after loading the view from its nib.
}
-(void)loadImageSuccess2:(cImageView *)imageView
{
    CGRect rect = self.pic.frame;
    rect.origin.x=0;
    rect.size = CGSizeMake(ScreenWidth,imageView.image.size.height/imageView.image.size.width*ScreenWidth);
    [self.pic setFrame:rect];
    [self.scrollView setContentSize:CGSizeMake(ScreenWidth, self.pic.bottom)];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)MathMoney:(id)sender {
    NSString *chang = self.chang.text;
    if ([chang isEqualToString:@""]||chang==nil) {
        [clsOtherFun ShowMsg:@"請輸入長"];
        [self.chang becomeFirstResponder];
        return;
    }
    NSString *kuan = self.kuan.text;
    if ([kuan isEqualToString:@""]||kuan==nil) {
        [clsOtherFun ShowMsg:@"請輸入寬"];
        [self.kuan becomeFirstResponder];
        return;
    }
    NSString *gao = self.gao.text;
    if ([gao isEqualToString:@""]||gao==nil) {
        [clsOtherFun ShowMsg:@"請輸入高"];
        [self.gao becomeFirstResponder];
        return;
    }
    NSString *Weight = self.Weight.text;
    if ([Weight isEqualToString:@""]||Weight==nil) {
        [clsOtherFun ShowMsg:@"請輸入重量"];
        [self.Weight becomeFirstResponder];
        return;
    }
    [clsOtherFun showLoadingView:@"正在獲取數據..."];
    if (!ants) {
        ants = [[clsAntsService alloc]init];
        ants.delegate = self;
    }
    [ants MathExpress:chang :kuan :gao :Weight :self.branch.BranchID];
}
-(void)getAntsDataSuccess:(NSInteger)type :(NSMutableDictionary *)pDictionary
{
    [clsOtherFun hideLoadingView];
    NSDictionary *dic = [pDictionary objectForKey:@"data"];
    NSString *status = [dic objectForKey:@"status"];
    if ([status integerValue]==200) {
        self.Money.text = [NSString stringWithFormat:@"%ld元",[[dic objectForKey:@"data"] integerValue]];
    }else{
        [clsOtherFun ShowMsg:[dic objectForKey:@"message"]];
    }
}
@end
